Skip to content

fix(db): avoid detached datasource in SQL Server pool creator - #1383

Merged
xuwei-fit2cloud merged 1 commit into
mainfrom
codex/fix-1330-sqlserver-pool
Sep 20, 2026
Merged

xuwei-fit2cloud merged 1 commit into
mainfrom
codex/fix-1330-sqlserver-pool

Conversation

@xuwei-fit2cloud

Copy link
Copy Markdown
Collaborator

Fixes #1330.

A SQL Server connection pool created from a request-scoped CoreDatasource retained that ORM object in its connection creator. After the request session closed, a later pool recycle or reconnect could read the expired ds.type attribute and raise DetachedInstanceError. Capture the datasource type while building the engine so future connections use a plain value.

The regression test creates the pool from a session-bound datasource, commits or rolls back and closes that session, then forces a reconnect from a later request. Both paths pass. The three existing pool manager tests also pass (5 total).

The same lifecycle was exercised with a reachable SQL Server instance (major version 16) through SQLBot's exec_sql: the original code reproduced DetachedInstanceError after forced recycle, while the fix returned the read-only query result. No database writes were performed. SQL Server 2019 and the full MaxKB-to-MCP workflow were not available for end-to-end verification.

Copilot AI lite review requested due to automatic review settings September 20, 2026 03:14
@xuwei-fit2cloud
xuwei-fit2cloud merged commit 518403e into main Sep 20, 2026
4 checks passed
@xuwei-fit2cloud
xuwei-fit2cloud deleted the codex/fix-1330-sqlserver-pool branch September 20, 2026 03:14

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The lifecycle fix is covered by regression tests with no unresolved issues.

Review effort: Lite
Findings: None

What changed in this PR

Fixes SQL Server pool reconnect failures after a request-scoped datasource session closes.

Changes:

  • Captures the datasource type as a plain value.
  • Adds commit and rollback lifecycle regression tests.
File Summary
backend/​tests/​test_sqlserver_pool_lifecycle.py Tests reconnect behavior after session closure.
backend/​apps/​db/​db.py Prevents detached ORM access during pool reconnection.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]Core Datasource at <> is not bound to a Session; attribute refresh operation cannot proceed

2 participants